"""/* Copyright(C) 2013, OpenSAR by Fan Wang(parai). All rights reserved.
 *
 * This file is part of OpenSAR.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * Email: parai@foxmail.com
 * Source Open At: https://github.com/parai/OpenSAR/
 */
"""

__all__=['Integer','GLInit','GAGet','GLGet','GHeader']

__root=None

def Integer(strnum):
    if(strnum.find('0x')!=-1 or strnum.find('0X')!=-1):
        return int(strnum,16)
    else:
        return int(strnum,10)

def GLInit(root):
    global __root
    __root=root

def GAGet(what,which):
    """ Gen Get Attribute"""
    return what.attrib[which]
    
def GLGet(what,which=None):
    """ Gen Get List
        used to get a sub node list from what if which is None,
        else get which fron what.
    """
    global __root
    if(which == None):
        if(__root.find(what) != None):
            return __root.find(what)
        else:
            return []
    else:
        if(what.find(which) != None):
            return what.find(which)
        else:
            return []
        
def GHeader(ModuleName):
    return """/*
* Configuration of module: %s
*
* Created by:   parai          
* Copyright:    (C)parai@foxmail.com  
*
* Configured for (MCU):    MinGW ...
*
* Module vendor:           ArcCore
* Generator version:       2.0.34
*
* Generated by easySAR Studio (https://github.com/parai/OpenSAR)
*/
"""%(ModuleName)
